{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2.2.3 创建你的第一个聊天机器人"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "%pip install openai LangChain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "from langchain.chat_models import ChatOpenAI\n",
    "from langchain.schema import (\n",
    "    AIMessage,\n",
    "    HumanMessage,\n",
    "    SystemMessage\n",
    ")\n",
    "chat = ChatOpenAI(temperature=0,openai_api_key=\"设置你的密钥\")\n",
    "chat.predict_messages([\n",
    "    HumanMessage(\n",
    "        content=(\n",
    "            \"Translate this sentence from English to French. \"\n",
    "            \"I love programming.\"\n",
    "        )\n",
    "    )\n",
    "])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "最后，的模型将返回一个 AIMessage 对象，它包含了这句英文的法文翻译。I love programming 翻译为法文：J'aime programmer."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "AIMessage(content=\"J'aime programmer.\", additional_kwargs={})"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
